<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i>待处理项目
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">

                <el-select v-model="query.projectStatus" placeholder="事项状态" class="handle-select mr10">
                    <el-option key="1" label="待处理" value=""></el-option>
                    <el-option key="2" label="未通过" value="2"></el-option>
                    <el-option key="3" label="已通过" value="1"></el-option>
<!--                    <el-option key="4" label="超时作废" value="RECYCLE"></el-option>-->

                </el-select>
                <el-input v-model="query.projectName" placeholder="模糊查询" class="handle-input mr10"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
            </div>
            <el-table
                    :data="tableData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                    @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="projectId" label="项目ID" width="80" align="center"></el-table-column>
                <el-table-column prop="projectName" label="项目名"></el-table-column>
                <el-table-column prop="projectContent" label="项目详情"></el-table-column>
                <el-table-column prop="projectTime" label="项目申请时间"></el-table-column>
                <el-table-column prop="projectStatus" label="项目状态" align="center"
                                 width="100">
                    <template slot-scope="scope">
                        <el-tag
                                :type="scope.row.projectStatus === '1' ? 'success' : 'warn'"
                                close-transition>{{scope.row.projectStatus}}
                        </el-tag>
                    </template>
                </el-table-column>

                <el-table-column prop="projectUpdateTime" label="处理时间"></el-table-column>
                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                icon="el-icon-edit"
                                @click="handleEdit(scope.$index, scope.row)"
                        >操作
                        </el-button>
<!--                        <el-button-->
<!--                                type="text"-->
<!--                                icon="el-icon-delete"-->
<!--                                class="red"-->
<!--                                @click="handleDelete(scope.$index, scope.row)"-->
<!--                        >回收-->
<!--                        </el-button>-->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                        background
                        layout="total, prev, pager, next"
                        :current-page="query.pageIndex"
                        :page-size="query.pageSize"
                        :total="pageTotal"
                        @current-change="handlePageChange"
                ></el-pagination>
            </div>
            
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="编辑" :visible.sync="editVisible" width="30%">
            <el-form ref="form" :model="form" label-width="70px">
                <el-form-item label="事项ID">
                    <el-input v-model="form.projectId"></el-input>
                </el-form-item>
                <el-form-item label="选择操作">
                    <el-select v-model="form.projectStatus">
                        <el-option key="1" label="直接批准" value="1"></el-option>
                        <el-option key="2" label="不批准" value="2"></el-option>
                        <el-option key="3" label="批准通过" value="3"></el-option>
<!--                        <el-option key="4" label="补充资料待复查" value="4"></el-option>-->
<!--                        <el-option key="5" label="超时作废" value="RECYCLE"></el-option>-->
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveEdit">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import {fetchData} from '../../api/index';

    export default {
        name: 'leadertable',
        data() {
            return {
                query: {
                    projectName: '',
                    projectStatus:'',
                    pageIndex: 1,
                    pageSize: 10
                },
                tableData: [],
                multipleSelection: [],
                delList: [],
                editVisible: false,
                pageTotal: 0,
                form: {
                    projectId:'',
                    projectStatus:'',
                },
                idx: -1,
                id: -1,
                userId:'',

            };

        },
        mounted() {
            this.getUserId({});
            this.getData({});
        },
        methods: {
            getUserId(userId){
                var vm = this;
                this.$axios.get('/selectLeaderId').then(resp => {
                    console.log(resp.data.data);
                    if (resp.data.success) {
                        vm.userId=resp.data.data;
                    }
                })
            },
            getData(params) {
                var vm = this;
                 var leaderId=1;
                 var projectStatus = params.projectStatus;
                 console.log(projectStatus+"aaaa")
                var projectName = params.projectName;
                var leaderId = params.leaderId;
                this.$axios.get('/chairmanPageList',{
                    params:{
                        projectStatus:projectStatus,
                        projectName:projectName,
                        leaderId:leaderId
                    }
                })
                    .then(resp => {
                    console.log(resp.data.data);
                    if (resp.data.success) {
                        //页面数据
                        vm.tableData = resp.data.data.records;
                        //总条数
                        vm.pageTotal = resp.data.data.total;
                        //当前页
                        vm.query.pageIndex = resp.data.data.current;
                    }
                })

            },
            // 触发搜索按钮
            handleSearch() {
                var q = this.query;
                var vm = this;
                var params = {projectStatus: q.projectStatus,projectName: q.projectName,leaderId:vm.userId}
                //alert("NMSL");
                vm.getData(params);
            },
            //上传文件


            // 多选操作 TODO
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            delAllSelection() {
                const length = this.multipleSelection.length;
                let str = '';
                this.delList = this.delList.concat(this.multipleSelection);
                for (let i = 0; i < length; i++) {
                    str += this.multipleSelection[i].name + ' ';
                }
                this.$message.error(`删除了${str}`);
                this.multipleSelection = [];
            },
            // 编辑操作
            handleEdit(index, row) {
                this.form = row;
                this.editVisible = true;
            },
            // 保存编辑
            saveEdit() {

                this.editVisible = false;
                // let formData = new FormData();
                // formData.append("projectId",this.form.projectId);
                // formData.append("sxStatus",this.form.projectStatus);
                var vm = this;
                var leaderId = this.userId;
                this.$axios.get('/dispacheroperation',{
                    params:{
                        projectStatus:this.form.projectStatus,
                        projectId:this.form.projectId,
                        leaderId:leaderId
                    }
                })
                    .then(resp => {
                        console.log(resp.data.data);
                        if (resp.data.success) {
                            this.$message.success(`审批成功`);
                        }
                        vm.handleSearch();
                    })
                // TODO

                this.$set(this.tableData, this.idx, this.form);
            },
            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, 'pageIndex', val);
                this.getData();
            }
        }
    };
</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }

    .table {
        width: 100%;
        font-size: 14px;
    }

    .red {
        color: #ff0000;
    }

    .mr10 {
        margin-right: 10px;
    }

</style>
